<!doctype html>
<html>
	<head>
		<title>支付订单</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0, user-scalable=no, width=device-width">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="assets/css/amazeui.min.css">
		<link rel="stylesheet" href="assets/css/style.css">
		<style>
		  .checkeder{color: #fb8714;background-image: url(assets/images/you.png); background-color:#eee; background-size:1.95rem; background-repeat: no-repeat; background-position: 97% center;}
		</style>
	</head>
	<body>
		<div class="containter">
		  <header data-am-widget="header" class="am-header am-header-default">
		    <div class="am-header-left am-header-nav">
		      <a href="javascript:;"onClick="javascript :history.back(-1);">
		        <img src="assets/images/left.png">
		      </a>
		    </div>
		    <h1 class="am-header-title">
		      支付订单
		    </h1>
		  </header>
		  <div class="paybody">
		    <div class="pay">
		      <h2 id="title"></h2>
		      <span class="span_outer">出发日期：<span id="time_start"></span></span>
		      <font>￥<b id="total_price">0</b></font>
		      <span class="span_outer">出发城市：<span id="depart_place"></span></span>
		      <span class="span_outer">出游人数：<span id="total_num">0</span>人</span>
		    </div>
		    <p>选择支付方式</p>
		    <ul>
		      <label class="am-radio">
		          <li>
		          <input style="line-height: inherit;margin:0;padding:0;" type="radio" name="radio1" value="" data-am-ucheck checked>
		          <img src="assets/images/zf1.png" alt="">微信支付
		          </li>
		      </label>
		      <!--<label class="am-radio">
		          <li>
		          <input style="line-height: inherit;" type="radio" name="radio1" value="" data-am-ucheck>
		          <img src="assets/images/zf2.png" alt="">支付宝支付
		          </li>
		      </label>-->
		    </ul>
		    <div class="pay_footer">
		      <span>实际付款：<font>￥<b style="font-weight: normal;" class="total_price">0</b></font></span>
		      <button>确认支付</button>
		    </div>
		  </div>
		</div>
		<script src="assets/js/jquery.min.js"></script>
		<script src="assets/js/allUse.js"></script>
		<script src="assets/js/amazeui.min.js"></script>
		<script>
				$(function(){
						if(sessionStorage.getItem("from_pay")){
						var arr=JSON.parse(sessionStorage.getItem("from_pay"));			
						$("#title").html(arr.title);
						$("#time_start").html(arr.time_start);
						$("#depart_place").html(sessionStorage.getItem("show_depart"));
						$("#total_num").html(arr.total_num);
						$("#total_price").html(arr.total_price);
						$(".total_price").html(arr.total_price);
					}
						var code=GetQueryString('code');var getOpenId=window.sessionStorage.getItem('openid');
						if(!code){
							window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx94e64e6cb29e11e5&redirect_uri=http%3A%2F%2Fapp1.sztravel.com.cn%2Fkouan%2Fpay.html&response_type=code&scope=snsapi_base&state=123#wechat_redirect"
						}else{
							//alert('code='+code+';openid='+getOpenId)
							if(!getOpenId){
								$.ajax({
									type:"post",
									headers: headers,
					 				url:url_enter+"/api/charge_order",
					 				async:true,
									data:{
										"order_no":arr.order_no,//订单号，string
							            "type":"wx",//支付渠道alipay-支付宝|wx-微信
										'code':code,
										"gzh":"1"
									},
									success:function(data){
										//alert(data.data);
										window.sessionStorage.setItem('openid',data.data);
										getOpenId=data.data;
									}
								})
								//点击支付start
									$('.pay_footer button').on('click',function(){
										$.ajax({
											type:"post",
											headers: headers,
							 				url:url_enter+"/api/charge_order",
							 				async:true,
											data:{
												"order_no":arr.order_no,//订单号，string
							               		"type":"wx",//支付渠道alipay-支付宝|wx-微信
							                	"pay_price":arr.total_price,//36800.00 支付总额 float
												"gzh":"1",
												"openid":getOpenId
											},
											success:function(data){
												//alert(data.data.msg.appid+','+data.data.msg.nonce_str+','+data.data.msg.signtype);
												function onBridgeReady(){
												   WeixinJSBridge.invoke(
												       'getBrandWCPayRequest', {
												           "appId":data.data.msg.appid,     //公众号名称，由商户传入     
												           "timeStamp":''+data.data.msg.timestamp,         //时间戳，自1970年以来的秒数     
												           "nonceStr":data.data.msg.nonce_str,//随机串     
												           "package":data.data.msg.package,     
												           "signType":data.data.msg.signtype,         //微信签名方式：     
												           "paySign":data.data.msg.sign //微信签名 
												       },
												       function(res){     
												           if(res.err_msg == "get_brand_wcpay_request:ok" ) {
												           	window.location.href="index.html";
												           }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
												           else{
												           
												           }
												       }
												   ); 
												}
												if (typeof WeixinJSBridge == "undefined"){
												   if( document.addEventListener ){
												       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
												   }else if (document.attachEvent){
												       document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
												       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
												   }
												}else{
												   onBridgeReady();
												}
											}
										});
									});
								//点击支付end
							}else{
								//点击支付start
									$('.pay_footer button').on('click',function(){
										$.ajax({
											type:"post",
											headers: headers,
							 				url:url_enter+"/api/charge_order",
							 				async:true,
											data:{
												"order_no":arr.order_no,//订单号，string
							               		"type":"wx",//支付渠道alipay-支付宝|wx-微信
							                	"pay_price":arr.total_price,//36800.00 支付总额 float
												"gzh":"1",
												"openid":getOpenId
											},
											success:function(data){
												//alert(data.data.msg.appid+','+data.data.msg.nonce_str+','+data.data.msg.signtype);
												function onBridgeReady(){
												   WeixinJSBridge.invoke(
												       'getBrandWCPayRequest', {
												           "appId":data.data.msg.appid,     //公众号名称，由商户传入     
												           "timeStamp":''+data.data.msg.timestamp,         //时间戳，自1970年以来的秒数     
												           "nonceStr":data.data.msg.nonce_str,//随机串     
												           "package":data.data.msg.package,     
												           "signType":data.data.msg.signtype,         //微信签名方式：     
												           "paySign":data.data.msg.sign //微信签名 
												       },
												       function(res){     
												           if(res.err_msg == "get_brand_wcpay_request:ok" ) {
												           	window.location.href="index.html";
												           }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
												           else{
												           
												           }
												       }
												   ); 
												}
												if (typeof WeixinJSBridge == "undefined"){
												   if( document.addEventListener ){
												       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
												   }else if (document.attachEvent){
												       document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
												       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
												   }
												}else{
												   onBridgeReady();
												}
											}
										});
									});
								//点击支付end
							}
							
						}
					
//						
//			appid:wx94e64e6cb29e11e5
//          mch_id:1273159101
//          trade_type:JSAPI
//          appsecret:a16df9245d11cf40ac76c76a3310ec84

 		    })
		</script>
	</body>
</html>






